package main

import "fmt"

//1、for,range 的k,v变量在整个遍历过程中共用，不能直接进行引用传递，即地址传递。
func main() {
	type tmp struct {
		value int
	}

	arr := []tmp{{value: 1}, {value: 2}, {value: 3}}
	var arr2 []*tmp
	for _, v := range arr {
		arr2 = append(arr2, &v)
	}

	for _, v := range arr2 {
		fmt.Println(v) //&{3}
	}
	fmt.Println(arr2) //[0xc000098008 0xc000098008 0xc000098008]  3,3,3

	a()
}

func a() {
	type tmp struct {
		value int
	}

	arr := []tmp{{value: 1}, {value: 2}, {value: 3}}
	var arr2 []*tmp
	for _, v := range arr {
		vNew := v
		arr2 = append(arr2, &vNew)
	}

	fmt.Println(arr2) //[0xc000098040 0xc000098048 0xc000098050]  1,2,3
}
